using System;
using System.Collections;
using System.Text;

namespace PaulRz.Util
{
	/// <summary>
	/// Helper class. Used for inter-encoding output building.
	/// </summary>
	public class ByteArrayBuilder
	{
		private ArrayList list=new ArrayList();

		public ByteArrayBuilder(string s)
		{
			Add(s);
		}


		public ByteArrayBuilder()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// Adds string to byteBuilder
		/// </summary>
		/// <param name="str">String must be a basic ASCII string. Characters with code higher than 127 will be encoded as question mark.</param>
		public void Add(string str)
		{
			list.AddRange(Encoding.ASCII.GetBytes(str));
		}

		public void Add(string str, Encoding enc )
		{
			list.AddRange(enc.GetBytes(str));
		}

		public void Add(ByteArrayBuilder builder)
		{
			list.AddRange(builder.GetBytes());
		}

		public byte[] GetBytes()
		{
			return (byte[]) list.ToArray(typeof(byte));
		}

		public override string ToString()
		{
			return Encoding.UTF8.GetString(GetBytes());
		}


	}
}
